package practice1_100;

public class MaxSum {
    public int maxSubArray(int[] nums) {
        int negNum=Integer.MIN_VALUE;
        int count=0,sum=0;
        for (int i = 0; i < nums.length; i++) {
            if(nums[i]<0&&nums[i]>negNum){
                negNum=nums[i];
            }else {
                sum+=nums[i];
                count++;
            }
        }
        if(count==0) return sum+negNum;
        return sum;
    }

    public static void main(String[] args) {
        int a=new MaxSum().maxSubArray(new int[]{-2,1,-3,4,-1,2,1,-5,4});
        System.out.println(a);
    }
}
